package top.suven.base.http.admin.user.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.user.model.User;
import top.suven.base.http.admin.user.model.UserRegisterInfo;

import java.util.List;

/**
 * @Title: UserWebDao.java
 * @Description: 用户的数据交互类
 * @author lixiangling
 * @date   2018/08/28 16:10:56
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface UserWebDao extends CommonCrudMapper<User> {
    @Select("<script> " +
    "select * from  rf_user where status='1' and enable_status='1' and user_id in " +
    "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
    "#{item} " +
    "</foreach> " +
    "</script>")
    @Results(
        id="user",
        value = {
            @Result(column = "user_id_tmp" , property = "userIdTmp"),
			@Result(column = "user_pwd" , property = "userPwd"),
			@Result(column = "user_name" , property = "userName"),
			@Result(column = "user_image_url" , property = "userImageUrl"),
			@Result(column = "user_gender" , property = "userGender"),
			@Result(column = "user_mobile_phone" , property = "userMobilePhone"),
			@Result(column = "mobile_carriers" , property = "mobileCarriers"),
			@Result(column = "user_email" , property = "userEmail"),
			@Result(column = "user_level" , property = "userLevel"),
			@Result(column = "user_status" , property = "userStatus"),
			@Result(column = "bind_pad_max" , property = "bindPadMax"),
			@Result(column = "reset_validata_code" , property = "resetValidataCode"),
			@Result(column = "reset_validata_time" , property = "resetValidataTime"),
			@Result(column = "register_ip" , property = "registerIp"),
			@Result(column = "login_type" , property = "loginType"),
			@Result(column = "login_ip" , property = "loginIp"),
			@Result(column = "login_time" , property = "loginTime"),
			@Result(column = "login_count" , property = "loginCount"),
			@Result(column = "status" , property = "status"),
			@Result(column = "creater" , property = "creater"),
			@Result(column = "create_time" , property = "createTime"),
			@Result(column = "modifier" , property = "modifier"),
			@Result(column = "modify_time" , property = "modifyTime"),
			@Result(column = "reorder" , property = "reorder"),
			@Result(column = "remark" , property = "remark"),
			@Result(column = "enable_status" , property = "enableStatus"),
			@Result(column = "user_birth" , property = "userBirth"),
			@Result(column = "card_id" , property = "cardId"),
			@Result(column = "first_apply_status" , property = "firstApplyStatus"),
			@Result(column = "left_online_time" , property = "leftOnlineTime"),
			@Result(column = "rbc_amount" , property = "rbcAmount"),
			@Result(column = "user_email_pwd" , property = "userEmailPwd"),
			@Result(column = "edu" , property = "edu"),
			@Result(column = "occupation" , property = "occupation"),
			@Result(column = "nick_name" , property = "nickName"),
			@Result(column = "address" , property = "address"),
			@Result(column = "qq" , property = "qq"),
			@Result(column = "wechat" , property = "wechat"),
			@Result(column = "mobile_bind_status" , property = "mobileBindStatus"),
			@Result(column = "pad_login_daily_status" , property = "padLoginDailyStatus"),
			@Result(column = "user_id" , property = "userId"),
			@Result(column = "apply_exper_status" , property = "applyExperStatus"),
			@Result(column = "invite_user_id" , property = "inviteUserId"),
			@Result(column = "user_source" , property = "userSource"),
			@Result(column = "first_probational_status" , property = "firstProbationalStatus"),
			@Result(column = "score_amount" , property = "scoreAmount"),
			@Result(column = "score_grade" , property = "scoreGrade"),
			@Result(column = "mailbox_verification_code" , property = "mailboxVerificationCode"),
			@Result(column = "email_expire_time" , property = "emailExpireTime"),
			@Result(column = "bind_pad_validata_code" , property = "bindPadValidataCode"),
			@Result(column = "bind_pad_expire_time" , property = "bindPadExpireTime"),
			@Result(column = "version" , property = "version"),
			@Result(column = "bound_pad_count" , property = "boundPadCount"),
			@Result(column = "client" , property = "client"),
			@Result(column = "imei" , property = "imei"),
			@Result(column = "limit_use" , property = "limitUse"),
			@Result(column = "external_user_id" , property = "externalUserId"),
			@Result(column = "auth_type" , property = "authType"),
			@Result(column = "user_classify" , property = "userClassify"),
			@Result(column = "openid" , property = "openid"),
			@Result(column = "openid_type" , property = "openidType"),
			@Result(column = "invite_type" , property = "inviteType"),
			@Result(column = "unionid" , property = "unionid")
        }
    )
    List<User> getSysRoleMenuByRoleCodeList(@Param("idList") List<Long> idList);
    /**
     * @Title: 删除用户信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 16:10:56
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE rf_user set status='0'"+
            "WHERE user_id IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<Long> idList);
    /**
     * @Title: 禁用用户信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/28 16:10:56
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
     @Update("<script> " +
             "UPDATE rf_user  " +
             "SET user_id = #{enableStatus}  " +
             "WHERE user_id IN " +
             "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
             "#{item} " +
             "</foreach> " +
             "</script>")
     void updateEnableStatus(@Param("enableStatus") String enableStatus, @Param("idList") List<Long> idList);

	@Select("<script> " +
			"select to_char(create_time, 'yyyy-MM-dd') as registerTime,client,count(0) as count from rf_user where status='1' "+
			"and create_time BETWEEN to_timestamp(to_char(current_timestamp- interval '1 week', 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"and to_timestamp(to_char(current_timestamp, 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"group by to_char(create_time, 'yyyy-MM-dd'),client order by to_char(create_time, 'yyyy-MM-dd'),client"+
			"</script>")
     List<UserRegisterInfo> getWeekRegisterCount();

	@Select("<script> " +
			"select to_char(create_time, 'yyyy-MM-dd') as registerTime,client,count(0) as count from rf_user where status='1' "+
			"and to_char(create_time, 'yyyy-MM-dd') in(to_char(current_timestamp- interval '1 day', 'yyyy-MM-dd'), "+
			"to_char(current_timestamp- interval '1 day'- interval '1 month', 'yyyy-MM-dd'), "+
			"to_char(current_timestamp- interval '1 day'- interval '1 year', 'yyyy-MM-dd') ) "+
			"group by to_char(create_time, 'yyyy-MM-dd'),client order by to_char(create_time, 'yyyy-MM-dd'),client desc"+
			"</script>")
	List<UserRegisterInfo> getRegisterStatistics();

	@Select("<script> " +
			"select to_char(create_time, 'yyyy-MM-dd') as registerTime,count(0) as count from rf_user where status='1' "+
			"and create_time BETWEEN to_timestamp(to_char(current_timestamp- interval '2 day', 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"and to_timestamp(to_char(current_timestamp, 'yyyy-MM-dd 00:00:00'),'yyyy-MM-dd HH24:mi:ss') "+
			"group by to_char(create_time, 'yyyy-MM-dd') order by to_char(create_time, 'yyyy-MM-dd')"+
			"</script>")
	List<UserRegisterInfo> getDayRegisterStatistics();
}